package com.yang.modules.common.threadpool;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

/**
 * @author: Billyang
 * @date: 2024/9/20 23:50
 */
@Slf4j
@Component
public class ThreadMonitor {
    @Autowired
    private ThreadPoolTaskExecutor executor;

    @Scheduled(cron = "0 0/10 * * * ?")
    public void monitor() {
        log.info("线程池信息：corePoolSize={}, maxPoolSize={}, poolSize={}, activeCount={},threadNamePrefix={} ",
                executor.getCorePoolSize(), executor.getMaxPoolSize(), executor.getPoolSize(), executor.getActiveCount(), executor.getThreadNamePrefix());
    }
}
